// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import createStore from './store/index'
import {
  Dialog,
  Tooltip,
  Radio,
  Button,
  RadioGroup,
  RadioButton,
  Loading,
  MessageBox,
  Checkbox,
  Message,
  Popover
} from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import iView from 'iview'
import Vuex from 'vuex'
import 'iview/dist/styles/iview.css'
import './assets/fonts/iconfont.css'
import '../static/css/base.css'
import axios from '@/assets/axios/axios'
import Notification from '@/components/notification'
import Tabs from '@/components/tabs'
Vue.prototype.axios = axios
Vue.use(Tooltip)
Vue.use(Radio)
Vue.use(RadioGroup)
Vue.use(RadioButton)
Vue.use(Button)
Vue.use(Checkbox)
Vue.use(Popover)
Vue.use(Dialog)
Vue.use(Loading.directive)

Vue.prototype.$loading = Loading.service
Vue.prototype.$msgbox = MessageBox
Vue.prototype.$message = Message
Vue.use(iView)
Vue.config.productionTip = false
Vue.use(Vuex)
Vue.use(Notification)
Vue.use(Tabs)
const store = createStore()
// 动态注册模块，eg:动态模块C
store.registerModule('c', {
  state: {
    modelecText: 'store module 56 value'
  }
})
/**
 *
 * 解绑store
 */
// store.unregisterModule('c')
/**
 * watch,第一个参数是值，第二个值是第一个值发生变化时，返回的值
 *
 */
store.watch((state) => state.count + 1, (newCount) => {
  console.log('new count', newCount)
})
/**
 * 订阅，每次mutation被调用，都会走这个回调函数
 */
store.subscribe((mutation, state) => {
  console.log(mutation.type, 'type')
  console.log(mutation.payload, '所接受参数')
})
store.subscribeAction((action, state) => {
  console.log(action.type, 'type')
  console.log(action.payload, '所接受参数')
})
// router 守卫
router.beforeEach((to, from, next) => {
  // 进行数据校验,验证登录
  // if(to.fullPath === '/index') {
  //     next('/login')   // 没有登录直接跳到登录页
  //     // next({path:'/login'})
  // }else{
  //     next()
  // }
  // to and from are both route objects. must call `next`.
  console.log('before each invoked')
  next()
})
router.beforeResolve((to, from, next) => {
  // to and from are both route objects. must call `next`.
  console.log('before resove invoked')
  next()
})
// 跳转之后才触发的
router.afterEach((to, from) => {
  // to and from are both route objects.
  console.log('before after invoked')
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

/**
 * 动态注册模块的功能
 * 应用场景：异步加载的时候拆分，有一个模块只有异步加载的时候，才会加载到
 *
 *
 *
 */
